﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Apmetrix
{

    /**
     * Apmetrix.cs
     * SDK
     * 
     * Created by Jon Holtan on 7/10/2013.
     * Copyright (c) 2012-2013 apMetrix. All rights reserved.
    **/

    /*
     * convenience class for handling logging of exceptions
     */
    class ApmetrixException : Exception
    {
        /*
         * Error: internal
         */
        private static readonly int ERROR_INTERNAL = 999;
        private string tag;
        private int status;

        ApmetrixException(String tag, String msg)
            : this(tag, ERROR_INTERNAL, msg)
        {
            
        }


        /**
             * Constructor for logging library exceptions
             */
       public ApmetrixException(String tag, int exceptionStatus, String msg)
            : base(msg)
        {
            
            this.tag = tag;
            status = exceptionStatus;

            if (status > Apmetrix.ERROR)
                // log exception as an error
                Console.WriteLine("ERROR: {0} {1}",tag, msg);
            else
                // log exception as a warning
                Console.WriteLine("WARNING: {0} {1}", tag, msg);

        }

        ApmetrixException(String tag, String msg, Exception ex)
            : base(msg)
        {
            this.tag = tag;
            // log exception as an error
            Console.WriteLine("ERROR: {0} {1} {2}", tag, msg, ex);
        }

        public String getTag()
        {
            return tag;
        }

        public int getExceptionStatus()
        {
            return status;
        }
    }
}
